package tau_sadna.tau_map;

import java.util.Iterator;
//
import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.android.view.MapView;
import org.mapsforge.map.layer.overlay.Marker;

import android.graphics.Bitmap;

public class SearchData implements Result{
	public int distace;
	public String matchingString;
	public TauLayer layer;

	@Override
	public MLString getName() {
		return layer.getName();
	}
	
	public SearchData(){
		this.distace = -1000;
		this.matchingString = null;
		this.layer = null;
	}
	
	public SearchData(int distance ,String match, TauLayer lay){
		this.distace = distance;
		this.matchingString = match;
		this.layer = lay;
	}

	@Override
	public void addTo(MapView mapView) {
		this.layer.addTo(mapView);
		centerAtLayer(mapView);
	}
	
	/**
	 * Center at the result if exactly one marker at result.
	 * @param mapView - the map view
	 */
	protected void centerAtLayer(MapView mapView){
		Iterator<Marker> iter = layer.markers.iterator();
		if(iter.hasNext()){
			LatLong latLong = iter.next().getLatLong();
			if(!iter.hasNext()){
				mapView.getModel().mapViewPosition.animateTo(latLong);
			}
		}
	}
	
	@Override
	public void removeFrom(MapView mapView){
		this.layer.removeFrom(mapView);
	}

	@Override
	public String getIconName() {
		return layer.pic_name;
	}

	@Override
	public LatLong getLatLong() {
		Iterator<Marker> iter = layer.markers.iterator();
		return iter.next().getLatLong();
	}
	
}
